<!DOCTYPE HTML>
<html lang="zh-CN">


<head>
    <meta charset="utf-8">
    <meta name="keywords" content="Kafka集群部署与Zookeepeerr集群部署实战, Java,Linux,Mysql,Redis,HTTP,操作系统,计算机网络,计算机组成原理,数据结构与算法,工具使用,性能优化">
    <meta name="description" content="本网站是个人兴趣爱好，总结分享经验，记录生活点滴的平台，希望在以后的学习旅途中，走出自己的风景。">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <!-- Global site tag (gtag.js) - Google Analytics -->


    <title>Kafka集群部署与Zookeepeerr集群部署实战 | 八戒取经路</title>
    <link rel="icon" type="image/png" href="/favicon.png">

    <link rel="stylesheet" type="text/css" href="/libs/awesome/css/all.css">
    <link rel="stylesheet" type="text/css" href="/libs/materialize/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/aos/aos.css">
    <link rel="stylesheet" type="text/css" href="/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/lightGallery/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/css/my.css">

    <script src="/libs/jquery/jquery.min.js"></script>

<meta name="generator" content="Hexo 5.4.0">
<style>.github-emoji { position: relative; display: inline-block; width: 1.2em; min-height: 1.2em; overflow: hidden; vertical-align: top; color: transparent; }  .github-emoji > span { position: relative; z-index: 10; }  .github-emoji img, .github-emoji .fancybox { margin: 0 !important; padding: 0 !important; border: none !important; outline: none !important; text-decoration: none !important; user-select: none !important; cursor: auto !important; }  .github-emoji img { height: 1.2em !important; width: 1.2em !important; position: absolute !important; left: 50% !important; top: 50% !important; transform: translate(-50%, -50%) !important; user-select: none !important; cursor: auto !important; } .github-emoji-fallback { color: inherit; } .github-emoji-fallback img { opacity: 0 !important; }</style>
<link rel="alternate" href="/atom.xml" title="八戒取经路" type="application/atom+xml">
<link rel="stylesheet" href="/css/prism-tomorrow.css" type="text/css"></head>




<body>
    <header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper container">
            <div class="brand-logo">
                <a href="/" class="waves-effect waves-light">
                    
                    <img src="/medias/logo.png" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">八戒取经路</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fas fa-bars"></i></a>
<ul class="right nav-menu">
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/" class="waves-effect waves-light">
      
      <i class="fas fa-home" style="zoom: 0.6;"></i>
      
      <span>首页</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/tags" class="waves-effect waves-light">
      
      <i class="fas fa-tags" style="zoom: 0.6;"></i>
      
      <span>标签</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/categories" class="waves-effect waves-light">
      
      <i class="fas fa-bookmark" style="zoom: 0.6;"></i>
      
      <span>分类</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/navigate" class="waves-effect waves-light">
      
      <i class="fas fa-location-arrow" style="zoom: 0.6;"></i>
      
      <span>导航</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/archives" class="waves-effect waves-light">
      
      <i class="fas fa-archive" style="zoom: 0.6;"></i>
      
      <span>归档</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/" class="waves-effect waves-light">

      
      <i class="fas fa-address-card" style="zoom: 0.6;"></i>
      
      <span>关于</span>
      <i class="fas fa-chevron-down" aria-hidden="true" style="zoom: 0.6;"></i>
    </a>
    <ul class="sub-nav menus_item_child ">
      
      <li>
        <a href="/about">
          
          <i class="fas fa-user-circle" style="margin-top: -20px; zoom: 0.6;"></i>
          
          <span>关于我</span>
        </a>
      </li>
      
      <li>
        <a href="/aboutme">
          
          <i class="fa fa-user-secret" style="margin-top: -20px; zoom: 0.6;"></i>
          
          <span>Another</span>
        </a>
      </li>
      
    </ul>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/contact" class="waves-effect waves-light">
      
      <i class="fas fa-comments" style="zoom: 0.6;"></i>
      
      <span>留言板</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/friends" class="waves-effect waves-light">
      
      <i class="fas fa-address-book" style="zoom: 0.6;"></i>
      
      <span>友情链接</span>
    </a>
    
  </li>
  
  <li>
    <a href="#searchModal" class="modal-trigger waves-effect waves-light">
      <i id="searchIcon" class="fas fa-search" title="搜索" style="zoom: 0.85;"></i>
    </a>
  </li>
</ul>


<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="/medias/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">八戒取经路</div>
        <div class="logo-desc">
            
            本网站是个人兴趣爱好，总结分享经验，记录生活点滴的平台，希望在以后的学习旅途中，走出自己的风景。
            
        </div>
    </div>

    

    <ul class="menu-list mobile-menu-list">
        
        <li class="m-nav-item">
	  
		<a href="/" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-home"></i>
			
			首页
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/tags" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-tags"></i>
			
			标签
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/categories" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-bookmark"></i>
			
			分类
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/navigate" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-location-arrow"></i>
			
			导航
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/archives" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-archive"></i>
			
			归档
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="javascript:;">
			
				<i class="fa-fw fas fa-address-card"></i>
			
			关于
			<span class="m-icon"><i class="fas fa-chevron-right"></i></span>
		</a>
            <ul  style="background:  ;" >
              
                <li>

                  <a href="/about " style="margin-left:75px">
				  
				   <i class="fa fas fa-user-circle" style="position: absolute;left:50px" ></i>
			      
		          <span>关于我</span>
                  </a>
                </li>
              
                <li>

                  <a href="/aboutme " style="margin-left:75px">
				  
				   <i class="fa fa fa-user-secret" style="position: absolute;left:50px" ></i>
			      
		          <span>Another</span>
                  </a>
                </li>
              
            </ul>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/contact" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-comments"></i>
			
			留言板
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/friends" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-address-book"></i>
			
			友情链接
		</a>
          
        </li>
        
        
        <li><div class="divider"></div></li>
        <li>
            <a href="https://github.com/" class="waves-effect waves-light" target="_blank">
                <i class="fab fa-github-square fa-fw"></i>Fork Me
            </a>
        </li>
        
    </ul>
</div>


        </div>

        
            <style>
    .nav-transparent .github-corner {
        display: none !important;
    }

    .github-corner {
        position: absolute;
        z-index: 10;
        top: 0;
        right: 0;
        border: 0;
        transform: scale(1.1);
    }

    .github-corner svg {
        color: #0f9d58;
        fill: #fff;
        height: 64px;
        width: 64px;
    }

    .github-corner:hover .octo-arm {
        animation: a 0.56s ease-in-out;
    }

    .github-corner .octo-arm {
        animation: none;
    }

    @keyframes a {
        0%,
        to {
            transform: rotate(0);
        }
        20%,
        60% {
            transform: rotate(-25deg);
        }
        40%,
        80% {
            transform: rotate(10deg);
        }
    }
</style>

<a href="https://github.com/" class="github-corner tooltipped hide-on-med-and-down" target="_blank"
   data-tooltip="Fork Me" data-position="left" data-delay="50">
    <svg viewBox="0 0 250 250" aria-hidden="true">
        <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
        <path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
              fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
        <path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
              fill="currentColor" class="octo-body"></path>
    </svg>
</a>
        
    </nav>

</header>

    



<div class="bg-cover pd-header post-cover" style="background-image: url('/medias/featureimages/9.jpg')">
    <div class="container" style="right: 0px;left: 0px;">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <h1 class="description center-align post-title">Kafka集群部署与Zookeepeerr集群部署实战</h1>
                </div>
            </div>
        </div>
    </div>
</div>




<main class="post-container content">

    
    <link rel="stylesheet" href="/libs/tocbot/tocbot.css">
<style>
    #articleContent h1::before,
    #articleContent h2::before,
    #articleContent h3::before,
    #articleContent h4::before,
    #articleContent h5::before,
    #articleContent h6::before {
        display: block;
        content: " ";
        height: 100px;
        margin-top: -100px;
        visibility: hidden;
    }

    #articleContent :focus {
        outline: none;
    }

    .toc-fixed {
        position: fixed;
        top: 64px;
    }

    .toc-widget {
        width: 345px;
        padding-left: 20px;
    }

    .toc-widget .toc-title {
        padding: 35px 0 15px 17px;
        font-size: 1.5rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    .toc-widget ol {
        padding: 0;
        list-style: none;
    }

    #toc-content {
        padding-bottom: 30px;
        overflow: auto;
    }

    #toc-content ol {
        padding-left: 10px;
    }

    #toc-content ol li {
        padding-left: 10px;
    }

    #toc-content .toc-link:hover {
        color: #42b983;
        font-weight: 700;
        text-decoration: underline;
    }

    #toc-content .toc-link::before {
        background-color: transparent;
        max-height: 25px;

        position: absolute;
        right: 23.5vw;
        display: block;
    }

    #toc-content .is-active-link {
        color: #42b983;
    }

    #floating-toc-btn {
        position: fixed;
        right: 15px;
        bottom: 76px;
        padding-top: 15px;
        margin-bottom: 0;
        z-index: 998;
    }

    #floating-toc-btn .btn-floating {
        width: 48px;
        height: 48px;
    }

    #floating-toc-btn .btn-floating i {
        line-height: 48px;
        font-size: 1.4rem;
    }
</style>
<div class="row">
    <div id="main-content" class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                    <div class="article-tag">
                        
                            <a href="/tags/Kafka/">
                                <span class="chip bg-color">Kafka</span>
                            </a>
                        
                            <a href="/tags/%E9%9B%86%E7%BE%A4/">
                                <span class="chip bg-color">集群</span>
                            </a>
                        
                            <a href="/tags/Zookeeper/">
                                <span class="chip bg-color">Zookeeper</span>
                            </a>
                        
                    </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                </div>
            </div>

            <div class="post-info">
                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-minus fa-fw"></i>发布日期:&nbsp;&nbsp;
                    2021-04-15
                </div>
                

                

                
                <div class="info-break-policy">
                    <i class="far fa-file-word fa-fw"></i>文章字数:&nbsp;&nbsp;
                    2.9k
                </div>
                

                

                
            </div>
        </div>
        <hr class="clearfix">

        

        

        <div class="card-content article-card-content">
            <div id="articleContent">
                <h1 id="ZooKeeper集群部署指南"><a href="#ZooKeeper集群部署指南" class="headerlink" title="ZooKeeper集群部署指南"></a><u><code>ZooKeeper集群部署指南</code></u></h1><h3 id="一、前言"><a href="#一、前言" class="headerlink" title="一、前言"></a><code>一、前言</code></h3><h4 id="1、ZooKeeper-简介"><a href="#1、ZooKeeper-简介" class="headerlink" title="1、ZooKeeper 简介"></a><code>1、ZooKeeper 简介</code></h4><p><code>ZooKeeper</code> 是一个开源的分布式应用程序协调服务，是 <code>Google</code> 的 <code>Chubby</code> 一个开源的实现。<code>ZooKeeper</code> 为分布式应用提供一致性服务，提供的功能包括：分布式同步（<code>Distributed Synchronization</code>）、命名服务（<code>Naming Service</code>）、集群维护（<code>Group Maintenance</code>）、分布式锁（<code>Distributed Lock</code>）等，简化分布式应用协调及其管理的难度，提供高性能的分布式服务。</p>
<p><code>ZooKeeper</code> 本身可以以单机模式安装运行，不过它的长处在于通过分布式 <code>ZooKeeper</code> 集群（一个 <code>Leader</code>，多个 <code>Follower</code> ），基于一定的策略来保证<code>ZooKeeper</code> 集群的稳定性和可用性，从而实现分布式应用的可靠性。</p>
<h4 id="2、ZooKeeper集群角色说明"><a href="#2、ZooKeeper集群角色说明" class="headerlink" title="2、ZooKeeper集群角色说明"></a><code>2、ZooKeeper集群角色说明</code></h4><p><code>ZooKeeper</code> 主要有领导者（<code>Leader</code>）、跟随者（<code>Follower</code>）和观察者（<code>Observer</code>）三种角色。</p>
<table>
<thead>
<tr>
<th>角色</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>领导者（<code>Leader</code>）</td>
<td>为客户端提供读和写的服务，负责投票的发起和决议，更新系统状态。</td>
</tr>
<tr>
<td>跟随者（<code>Follower</code>）</td>
<td>为客户端提供读服务，如果是写服务则转发给 <code>Leader</code>。在选举过程中参与投票。</td>
</tr>
<tr>
<td>观察者（<code>Observer</code>）</td>
<td>为客户端提供读服务器，如果是写服务则转发给 <code>Leader</code>。不参与选举过程中的投票，也不参与“过半写成功”策略。在不影响写性能的情况下提升集群的读性能。此角色于 <code>Zookeeper3.3</code> 系列新增的角色。</td>
</tr>
</tbody></table>
<h3 id="二、准备工作"><a href="#二、准备工作" class="headerlink" title="二、准备工作"></a><code>二、准备工作</code></h3><h4 id="1、集群节点规划"><a href="#1、集群节点规划" class="headerlink" title="1、集群节点规划"></a><code>1、集群节点规划</code></h4><p><code>ZooKeeper</code> 在提供分布式锁等服务的时候需要过半数的节点可用。另外高可用的诉求来说节点的个数必须&gt;1，所以 <code>ZooKeeper</code> 集群需要是 <code>&gt;1</code> 的奇数节点。例如 <code>3、5、7</code> 等等。<br>本次我们规划三个节点，操作系统选用 <code>CnetOS 7</code></p>
<table>
<thead>
<tr>
<th>节点名</th>
<th>IP</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>zk01</td>
<td>192.168.88.11</td>
<td>ZooKeeper节点</td>
</tr>
<tr>
<td>zk02</td>
<td>192.168.88.12</td>
<td>ZooKeeper节点</td>
</tr>
<tr>
<td>zk03</td>
<td>192.168.88.13</td>
<td>ZooKeeper节点</td>
</tr>
</tbody></table>
<h4 id="2、软件版本说明"><a href="#2、软件版本说明" class="headerlink" title="2、软件版本说明"></a><code>2、软件版本说明</code></h4><table>
<thead>
<tr>
<th>项</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>Linux Server</td>
<td>CentOS 7</td>
</tr>
<tr>
<td>JDK</td>
<td>1.8.0_161</td>
</tr>
<tr>
<td>ZooKeeper</td>
<td>3.4.11</td>
</tr>
</tbody></table>
<h4 id="3、部署JDK8"><a href="#3、部署JDK8" class="headerlink" title="3、部署JDK8"></a><code>3、部署JDK8</code></h4><p>所有节点均需要安装 <code>JDK8</code><br>参考<a target="_blank" rel="noopener" href="https://ken.io/note/centos-java-setup"><code>CentOS下部署Java7/Java8</code></a></p>
<h3 id="三、部署ZooKeeper"><a href="#三、部署ZooKeeper" class="headerlink" title="三、部署ZooKeeper"></a><code>三、部署ZooKeeper</code></h3><p>本次一共要部署三个 <code>ZooKeeper</code> 节点，所有文中没有指定机器的操作都表示每个节点都要执行该操作</p>
<h4 id="1、下载ZooKeeper-amp-基础准备"><a href="#1、下载ZooKeeper-amp-基础准备" class="headerlink" title="1、下载ZooKeeper&amp;基础准备"></a><code>1、下载ZooKeeper&amp;基础准备</code></h4><ul>
<li>下载 <code>ZooKeeper</code></li>
</ul>
<p><a target="_blank" rel="noopener" href="https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/">官方镜像选择</a></p>
<pre class=" language-bash"><code class="language-bash"><span class="token function">cd</span> /home/download
<span class="token function">wget</span> https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.5.9/apache-zookeeper-3.5.9-bin.tar.gz
</code></pre>
<ul>
<li>创建 <code>ZooKeeper</code> 相关目录</li>
</ul>
<pre class=" language-bash"><code class="language-bash"><span class="token comment" spellcheck="true">#创建应用目录</span>
<span class="token function">mkdir</span> /usr/zookeeper

<span class="token comment" spellcheck="true">#创建数据目录</span>
<span class="token function">mkdir</span> /zookeeper
<span class="token function">mkdir</span> /zookeeper/data
<span class="token function">mkdir</span> /zookeeper/logs
</code></pre>
<ul>
<li>解压到指定目录</li>
</ul>
<pre class=" language-bash"><code class="language-bash"><span class="token function">tar</span> -zvxf apache-zookeeper-3.5.9-bin.tar.gzz -C /usr/zookeeper
</code></pre>
<ul>
<li>配置环境变量</li>
</ul>
<pre class=" language-bash"><code class="language-bash"><span class="token comment" spellcheck="true">#修改环境变量文件</span>
<span class="token function">vi</span> /etc/profile

<span class="token comment" spellcheck="true">#增加以下内容</span>
<span class="token function">export</span> ZOOKEEPER_HOME<span class="token operator">=</span>/usr/zookeeper/apache-zookeeper-3.5.9-bin.tar.gz
<span class="token function">export</span> PATH<span class="token operator">=</span><span class="token variable">$ZOOKEEPER_HOME</span>/bin:<span class="token variable">$PATH</span>

<span class="token comment" spellcheck="true">#使环境变量生效</span>
<span class="token function">source</span> /etc/profile

<span class="token comment" spellcheck="true">#查看配置结果</span>
<span class="token keyword">echo</span> <span class="token variable">$ZOOKEEPER_HOME</span>
</code></pre>
<p>既然已配置环境变量，为了方便访问 <code>ZooKeeper</code> 目录<br>后续通过 <code>$ZOOKEEPER_HOME</code> 代替 <code>/usr/zookeeper/apache-zookeeper-3.5.9-bin.tar.gz</code></p>
<h4 id="2、配置ZooKeeper"><a href="#2、配置ZooKeeper" class="headerlink" title="2、配置ZooKeeper"></a><code>2、配置ZooKeeper</code></h4><ul>
<li><code>ZooKeeper</code> 基础配置</li>
</ul>
<pre><code>#进入ZooKeeper配置目录
cd $ZOOKEEPER_HOME/conf

#新建配置文件
vi zoo.cfg

#写入以下内容并保存

tickTime=2000
initLimit=10
syncLimit=5
dataDir=/zookeeper/data
dataLogDir=/zookeeper/logs
clientPort=2181
server.1=192.168.88.11:2888:3888
server.2=192.168.88.12:2888:3888
server.3=192.168.88.13:2888:3888
</code></pre>
<ul>
<li>配置节点标识</li>
</ul>
<p><code>zk01</code>：</p>
<pre class=" language-bash"><code class="language-bash"><span class="token keyword">echo</span> <span class="token string">"1"</span> <span class="token operator">></span> /zookeeper/data/myid
</code></pre>
<p><code>zk02</code>：</p>
<pre class=" language-bash"><code class="language-bash"><span class="token keyword">echo</span> <span class="token string">"2"</span> <span class="token operator">></span> /zookeeper/data/myid
</code></pre>
<p><code>zk03</code>：</p>
<pre class=" language-bash"><code class="language-bash"><span class="token keyword">echo</span> <span class="token string">"3"</span> <span class="token operator">></span> /zookeeper/data/myid
</code></pre>
<ul>
<li>防火墙配置</li>
</ul>
<pre class=" language-bash"><code class="language-bash"><span class="token comment" spellcheck="true">#开放端口</span>
firewall-cmd --add-port<span class="token operator">=</span>2181/tcp --permanent
firewall-cmd --add-port<span class="token operator">=</span>2888/tcp --permanent
firewall-cmd --add-port<span class="token operator">=</span>3888/tcp --permanent

<span class="token comment" spellcheck="true">#重新加载防火墙配置</span>
firewall-cmd --reload
</code></pre>
<h4 id="3、启动ZooKeeper"><a href="#3、启动ZooKeeper" class="headerlink" title="3、启动ZooKeeper"></a><code>3、启动ZooKeeper</code></h4><pre class=" language-bash"><code class="language-bash"><span class="token comment" spellcheck="true">#进入ZooKeeper bin目录</span>
<span class="token function">cd</span> <span class="token variable">$ZOOKEEPER_HOME</span>/bin

<span class="token comment" spellcheck="true">#启动</span>
sh zkServer.sh start
</code></pre>
<p>出现以下字样表示启动成功：</p>
<blockquote>
<p>ZooKeeper JMX enabled by default<br>Using config: /usr/zookeeper/apache-zookeeper-3.5.9-bin.tar.gz/bin/../conf/zoo.cfg<br>Starting zookeeper … STARTED</p>
</blockquote>
<h3 id="四、集群查看-amp-连接测试"><a href="#四、集群查看-amp-连接测试" class="headerlink" title="四、集群查看&amp;连接测试"></a><code>四、集群查看&amp;连接测试</code></h3><h4 id="1、查看节点状态"><a href="#1、查看节点状态" class="headerlink" title="1、查看节点状态"></a><code>1、查看节点状态</code></h4><pre class=" language-bash"><code class="language-bash">sh <span class="token variable">$ZOOKEEPER_HOME</span>/bin/zkServer.sh status

<span class="token comment" spellcheck="true">#状态信息</span>
ZooKeeper JMX enabled by default
Using config: /usr/zookeeper/apache-zookeeper-3.5.9-bin.tar.gz/bin/<span class="token punctuation">..</span>/conf/zoo.cfg
Mode: follower

<span class="token comment" spellcheck="true">#如果为领导者节点则Mode:leader</span>
</code></pre>
<h4 id="2、客户端连接测试"><a href="#2、客户端连接测试" class="headerlink" title="2、客户端连接测试"></a><code>2、客户端连接测试</code></h4><p>这里随机选其中一个节点作为客户端连接其他节点即可</p>
<pre class=" language-bash"><code class="language-bash"><span class="token comment" spellcheck="true">#指定Server进行连接</span>
sh <span class="token variable">$ZOOKEEPER_HOME</span>/bin/zkCli.sh -server 192.168.88.13:2181

<span class="token comment" spellcheck="true">#正常连接后会进入ZooKeeper命令行，显示如下：</span>
<span class="token punctuation">[</span>zk: 192.168.88.13:2181<span class="token punctuation">(</span>CONNECTED<span class="token punctuation">)</span> 0<span class="token punctuation">]</span>
</code></pre>
<p>输入命令测试：</p>
<pre class=" language-bash"><code class="language-bash"><span class="token comment" spellcheck="true">#查看ZooKeeper根</span>
<span class="token punctuation">[</span>zk: 192.168.88.13:2181<span class="token punctuation">(</span>CONNECTED<span class="token punctuation">)</span> 0<span class="token punctuation">]</span> <span class="token function">ls</span> /
<span class="token punctuation">[</span>zookeeper<span class="token punctuation">]</span>
</code></pre>
<h3 id="五、备注"><a href="#五、备注" class="headerlink" title="五、备注"></a><code>五、备注</code></h3><h4 id="1、ZooKeeper常用配置项说明"><a href="#1、ZooKeeper常用配置项说明" class="headerlink" title="1、ZooKeeper常用配置项说明"></a><code>1、ZooKeeper常用配置项说明</code></h4><table>
<thead>
<tr>
<th>配置项</th>
<th>名称</th>
<th>ken.io 的说明</th>
</tr>
</thead>
<tbody><tr>
<td>tickTime</td>
<td>CS通信心跳间隔</td>
<td>服务器之间或客户端与服务器之间维持心跳的时间间隔，也就是每间隔 tickTime 时间就会发送一个心跳。tickTime以毫秒为单位。</td>
</tr>
<tr>
<td>initLimit</td>
<td>LF初始通信时限</td>
<td>集群中的follower服务器(F)与leader服务器(L)之间初始连接时能容忍的最多心跳数</td>
</tr>
<tr>
<td>syncLimit</td>
<td>LF同步通信时限</td>
<td>集群中的follower服务器与leader服务器之间请求和应答之间能容忍的最多心跳数</td>
</tr>
<tr>
<td>dataDir</td>
<td>数据文件目录</td>
<td>Zookeeper保存数据的目录，默认情况下，Zookeeper将写数据的日志文件也保存在这个目录里</td>
</tr>
<tr>
<td>dataLogDir</td>
<td>日志文件目录</td>
<td>Zookeeper保存日志文件的目录</td>
</tr>
<tr>
<td>clientPort</td>
<td>客户端连接端口</td>
<td>客户端连接 Zookeeper 服务器的端口，Zookeeper 会监听这个端口，接受客户端的访问请求</td>
</tr>
<tr>
<td>server.N</td>
<td>服务器名称与地址</td>
<td>从N开始依次为：服务编号、服务地址、LF通信端口、选举端口；例如：server.1=192.168.88.11:2888:3888</td>
</tr>
</tbody></table>
<h3 id="六、参考文献"><a href="#六、参考文献" class="headerlink" title="六、参考文献"></a><code>六、参考文献</code></h3><p><a href="ttps://ken.io/note/zookeeper-cluster-deploy-guide"><code>参考文献</code></a></p>
<hr>
<h1 id="Kafka集群部署指南"><a href="#Kafka集群部署指南" class="headerlink" title="Kafka集群部署指南"></a><u><code>Kafka集群部署指南</code></u></h1><h3 id="一、前言-1"><a href="#一、前言-1" class="headerlink" title="一、前言"></a><code>一、前言</code></h3><h4 id="1、Kafka简介"><a href="#1、Kafka简介" class="headerlink" title="1、Kafka简介"></a><code>1、Kafka简介</code></h4><p><code>Kafka</code> 是一个开源的分布式消息引擎/消息中间件，同时 <code>Kafka</code> 也是一个流处理平台。<code>Kakfa</code> 支持以发布/订阅的方式在应用间传递消息，同时并基于消息功能添加了 <code>Kafka Connect、Kafka Streams</code> 以支持连接其他系统的数据(<a target="_blank" rel="noopener" href="https://ken.io/note/elk-deploy-guide">Elasticsearch</a>、<a target="_blank" rel="noopener" href="https://ken.io/note/hadoop-cluster-deploy-guide">Hadoop</a>等)</p>
<p><code>Kafka</code> 最核心的最成熟的还是他的消息引擎，所以 <code>Kafka</code> 大部分应用场景还是用来作为消息队列削峰平谷。另外，<code>Kafka</code> 也是目前性能最好的消息中间件。</p>
<h4 id="2、Kafka-架构"><a href="#2、Kafka-架构" class="headerlink" title="2、Kafka 架构"></a><code>2、Kafka 架构</code></h4><p><img src="https://gitee.com/CodeJourney/source_file/raw/master/blog_img/13570814-c5656ebf67a57db3.png" alt="kafka架构图"></p>
<p>在 <code>Kafka</code> 集群(<code>Cluster</code>)中，一个 <code>Kafka</code> 节点就是一个 <code>Broker</code>，消息由 <code>Topic</code> 来承载，可以存储在 <code>1</code> 个或多个 <code>Partition</code> 中。发布消息的应用为<code>Producer</code>、消费消息的应用为 <code>Consumer</code>，多个 <code>Consumer</code> 可以促成 <code>Consumer Group</code> 共同消费一个 <code>Topic</code> 中的消息。</p>
<table>
<thead>
<tr>
<th>概念/对象</th>
<th>简单说明</th>
</tr>
</thead>
<tbody><tr>
<td>Broker</td>
<td>Kafka节点</td>
</tr>
<tr>
<td>Topic</td>
<td>主题，用来承载消息</td>
</tr>
<tr>
<td>Partition</td>
<td>分区，用于主题分片存储</td>
</tr>
<tr>
<td>Producer</td>
<td>生产者，向主题发布消息的应用</td>
</tr>
<tr>
<td>Consumer</td>
<td>消费者，从主题订阅消息的应用</td>
</tr>
<tr>
<td>Consumer Group</td>
<td>消费者组，由多个消费者组成</td>
</tr>
</tbody></table>
<h4 id="3、准备工作"><a href="#3、准备工作" class="headerlink" title="3、准备工作"></a><code>3、准备工作</code></h4><h4 id="1、Kafka-服务器"><a href="#1、Kafka-服务器" class="headerlink" title="1、Kafka 服务器"></a>1、<code>Kafka</code> 服务器</h4><p>准备 <code>3</code> 台 <code>CentOS</code> 服务器，并配置好静态<code>IP</code>、主机名</p>
<table>
<thead>
<tr>
<th>服务器名</th>
<th>IP</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>kafka01</td>
<td>192.168.88.51</td>
<td>Kafka节点1</td>
</tr>
<tr>
<td>kafka02</td>
<td>192.168.88.52</td>
<td>Kafka节点2</td>
</tr>
<tr>
<td>kafka03</td>
<td>192.168.88.53</td>
<td>Kafka节点3</td>
</tr>
</tbody></table>
<p>软件版本说明</p>
<table>
<thead>
<tr>
<th>项</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>Linux Server</td>
<td>CentOS 7</td>
</tr>
<tr>
<td>Kafka</td>
<td>2.3.0</td>
</tr>
</tbody></table>
<h4 id="2、ZooKeeper集群"><a href="#2、ZooKeeper集群" class="headerlink" title="2、ZooKeeper集群"></a><code>2、ZooKeeper集群</code></h4><p><code>Kakfa</code> 集群需要依赖 <code>ZooKeeper</code> 存储 <code>Broker、Topic</code> 等信息，这里我们部署三台 <code>ZK</code></p>
<table>
<thead>
<tr>
<th>服务器名</th>
<th>IP</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>zk01</td>
<td>192.168.88.21</td>
<td>ZooKeeper节点</td>
</tr>
<tr>
<td>zk02</td>
<td>192.168.88.22</td>
<td>ZooKeeper节点</td>
</tr>
<tr>
<td>zk03</td>
<td>192.168.88.23</td>
<td>ZooKeeper节点</td>
</tr>
</tbody></table>
<p>部署过程参考前面的 <code>Zookeeper 集群部署指南</code></p>
<h3 id="二、部署过程"><a href="#二、部署过程" class="headerlink" title="二、部署过程"></a><code>二、部署过程</code></h3><h4 id="1、应用-amp-数据目录"><a href="#1、应用-amp-数据目录" class="headerlink" title="1、应用&amp;数据目录"></a><code>1、应用&amp;数据目录</code></h4><pre class=" language-bash"><code class="language-bash"><span class="token comment" spellcheck="true">#创建应用目录</span>
<span class="token function">mkdir</span> /usr/kafka

<span class="token comment" spellcheck="true">#创建Kafka数据目录</span>
<span class="token function">mkdir</span> /kafka
<span class="token function">mkdir</span> /kafka/logs
<span class="token function">chmod</span> 777 -R /kafka
</code></pre>
<h4 id="2、下载-amp-解压"><a href="#2、下载-amp-解压" class="headerlink" title="2、下载&amp;解压"></a><code>2、下载&amp;解压</code></h4><p><a target="_blank" rel="noopener" href="https://kafka.apache.org/downloads"><code>Kafka官方下载地址</code></a><br>这次我下载的是 <code>2.3.0</code> 版本</p>
<pre class=" language-bash"><code class="language-bash"><span class="token comment" spellcheck="true">#创建并进入下载目录</span>
<span class="token function">mkdir</span> /home/downloads
<span class="token function">cd</span> /home/downloads

<span class="token comment" spellcheck="true">#下载安装包</span>
<span class="token function">wget</span> https://mirrors.tuna.tsinghua.edu.cn/apache/kafka/2.7.0/kafka_2.13-2.7.0.tgz 

<span class="token comment" spellcheck="true">#解压到应用目录</span>
<span class="token function">tar</span> -zvxf kafka_2.13-2.7.0.tgz -C /usr/kafka
</code></pre>
<blockquote>
<p>kkafka_2.13-2.7.0.tgz 其中2.13是Scala编译器的版本，2.7.0才是Kafka的版本</p>
</blockquote>
<h4 id="3、Kafka节点配置"><a href="#3、Kafka节点配置" class="headerlink" title="3、Kafka节点配置"></a><code>3、Kafka节点配置</code></h4><pre class=" language-bash"><code class="language-bash"><span class="token comment" spellcheck="true">#进入应用目录</span>
<span class="token function">cd</span> /usr/kafka/kafka_2.13-2.7.0.tgz/

<span class="token comment" spellcheck="true">#修改配置文件</span>
<span class="token function">vi</span> config/server.properties
</code></pre>
<h4 id="通用配置"><a href="#通用配置" class="headerlink" title="通用配置"></a>通用配置</h4><p>配置日志目录、指定 <code>ZooKeeper</code> 服务器</p>
<pre class=" language-bash"><code class="language-bash"><span class="token comment" spellcheck="true"># A comma separated list of directories under which to store log files</span>
log.dirs<span class="token operator">=</span>/kafka/logs

<span class="token comment" spellcheck="true"># root directory for all kafka znodes.</span>
zookeeper.connect<span class="token operator">=</span>192.168.88.21:2181,192.168.88.22:2181,192.168.88.23:2181
</code></pre>
<h4 id="分节点配置-也是在-config-server-properties-中配置"><a href="#分节点配置-也是在-config-server-properties-中配置" class="headerlink" title="分节点配置(也是在 config/server.properties 中配置)"></a>分节点配置(也是在 <code>config/server.properties</code> 中配置)</h4><ul>
<li><code>Kafka01</code></li>
</ul>
<pre class=" language-bash"><code class="language-bash">broker.id<span class="token operator">=</span>0

<span class="token comment" spellcheck="true">#listeners=PLAINTEXT://:9092</span>
listeners<span class="token operator">=</span>PLAINTEXT://192.168.88.51:9092
</code></pre>
<ul>
<li><code>Kafka02</code></li>
</ul>
<pre class=" language-bash"><code class="language-bash">broker.id<span class="token operator">=</span>1

<span class="token comment" spellcheck="true">#listeners=PLAINTEXT://:9092</span>
listeners<span class="token operator">=</span>PLAINTEXT://192.168.88.52:9092
</code></pre>
<ul>
<li><code>Kafka03</code></li>
</ul>
<pre class=" language-bash"><code class="language-bash">broker.id<span class="token operator">=</span>2

<span class="token comment" spellcheck="true">#listeners=PLAINTEXT://:9092</span>
listeners<span class="token operator">=</span>PLAINTEXT://192.168.88.53:9092
</code></pre>
<h4 id="4、防火墙配置"><a href="#4、防火墙配置" class="headerlink" title="4、防火墙配置"></a><code>4、防火墙配置</code></h4><pre class=" language-bash"><code class="language-bash"><span class="token comment" spellcheck="true">#开放端口</span>
firewall-cmd --add-port<span class="token operator">=</span>9092/tcp --permanent

<span class="token comment" spellcheck="true">#重新加载防火墙配置</span>
firewall-cmd --reload
</code></pre>
<h4 id="5、启动-Kafka"><a href="#5、启动-Kafka" class="headerlink" title="5、启动 Kafka"></a><code>5、启动 Kafka</code></h4><pre class=" language-bash"><code class="language-bash"><span class="token comment" spellcheck="true">#进入kafka根目录</span>
<span class="token function">cd</span> /usr/kafka/kafka_2.13-2.7.0.tgz/
<span class="token comment" spellcheck="true">#启动</span>
/bin/kafka-server-start.sh config/server.properties <span class="token operator">&amp;</span>

<span class="token comment" spellcheck="true">#启动成功输出示例(最后几行)</span>
<span class="token punctuation">[</span>2019-06-26 21:48:57,183<span class="token punctuation">]</span> INFO Kafka commitId: fc1aaa116b661c8a <span class="token punctuation">(</span>org.apache.kafka.common.utils.AppInfoParser<span class="token punctuation">)</span>
<span class="token punctuation">[</span>2019-06-26 21:48:57,183<span class="token punctuation">]</span> INFO Kafka startTimeMs: 1561531737175 <span class="token punctuation">(</span>org.apache.kafka.common.utils.AppInfoParser<span class="token punctuation">)</span>
<span class="token punctuation">[</span>2019-06-26 21:48:57,185<span class="token punctuation">]</span> INFO <span class="token punctuation">[</span>KafkaServer id<span class="token operator">=</span>0<span class="token punctuation">]</span> started <span class="token punctuation">(</span>kafka.server.KafkaServer<span class="token punctuation">)</span>
</code></pre>
<h3 id="三、Kafka-测试"><a href="#三、Kafka-测试" class="headerlink" title="三、Kafka 测试"></a><code>三、Kafka 测试</code></h3><h4 id="1、创建Topic"><a href="#1、创建Topic" class="headerlink" title="1、创建Topic"></a><code>1、创建Topic</code></h4><p>在 <code>kafka01(Broker)</code> 上创建测试 <code>Tpoic：test-ken-io</code>，这里我们指定了 <code>3</code> 个副本、<code>1</code> 个分区</p>
<pre class=" language-bash"><code class="language-bash">bin/kafka-topics.sh --create --bootstrap-server 192.168.88.51:9092 --replication-factor 3 --partitions 1 --topic test-ken-io
</code></pre>
<p><code>Topic</code> 在 <code>kafka01</code>上创建后也会同步到集群中另外两个 <code>Broker：kafka02、kafka03</code></p>
<h4 id="2、查看Topic"><a href="#2、查看Topic" class="headerlink" title="2、查看Topic"></a><code>2、查看Topic</code></h4><p>我们可以通过命令列出指定 <code>Broker</code> 的</p>
<pre class=" language-bash"><code class="language-bash">bin/kafka-topics.sh --list --bootstrap-server 192.168.88.52:9092
</code></pre>
<h4 id="3、发送消息"><a href="#3、发送消息" class="headerlink" title="3、发送消息"></a><code>3、发送消息</code></h4><p>这里我们向 <code>Broker(id=0)</code> 的 <code>Topic=test-ken-io</code> 发送消息</p>
<pre class=" language-bash"><code class="language-bash">bin/kafka-console-producer.sh --broker-list  192.168.88.51:9092  --topic test-ken-io

<span class="token comment" spellcheck="true">#消息内容</span>
<span class="token operator">></span> <span class="token function">test</span> by ken.io
</code></pre>
<h4 id="4、消费消息"><a href="#4、消费消息" class="headerlink" title="4、消费消息"></a><code>4、消费消息</code></h4><p>在 <code>Kafka02</code> 上消费 <code>Broker03</code> 的消息</p>
<pre class=" language-bash"><code class="language-bash">bin/kafka-console-consumer.sh --bootstrap-server 192.168.88.53:9092 --topic test-ken-io --from-beginning
</code></pre>
<p>在 <code>Kafka03</code>上消费 <code>Broker02</code> 的消息</p>
<pre class=" language-bash"><code class="language-bash">bin/kafka-console-consumer.sh --bootstrap-server 192.168.88.52:9092 --topic test-ken-io --from-beginning
</code></pre>
<p>然后均能收到消息</p>
<pre class=" language-bash"><code class="language-bash"><span class="token function">test</span> by ken.io
</code></pre>
<p>如上的操作，多个 <code>consumer</code> 客户端都能收到消息，这是因为这两个消费消息的命令是建立了两个不同的 <code>Consumer</code><br>如果我们启动 <code>Consumer</code> 指定 <code>Consumer Group Id</code> 就可以作为一个消费组协同工，<code>1</code> 个消息同时只会被一个 <code>Consumer</code> 消费到</p>
<pre class=" language-bash"><code class="language-bash">bin/kafka-console-consumer.sh --bootstrap-server 192.168.88.53:9092 --topic test-ken-io --from-beginning --group testgroup_ken <span class="token comment" spellcheck="true">##启动消费者，并指定组</span>

bin/kafka-console-consumer.sh --bootstrap-server 192.168.88.52:9092 --topic test-ken-io --from-beginning --group testgroup_ken <span class="token comment" spellcheck="true">##启动消费者，并指定组</span>
</code></pre>
<h3 id="四、备注"><a href="#四、备注" class="headerlink" title="四、备注"></a><code>四、备注</code></h3><h4 id="1、Kafka常用配置项说明"><a href="#1、Kafka常用配置项说明" class="headerlink" title="1、Kafka常用配置项说明"></a><code>1、Kafka常用配置项说明</code></h4><p><code>Kafka</code> 常用 <code>Broker</code> 配置说明：</p>
<table>
<thead>
<tr>
<th>配置项</th>
<th>默认值/示例值</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>broker.id</td>
<td>0</td>
<td>Broker唯一标识</td>
</tr>
<tr>
<td>listeners</td>
<td>PLAINTEXT://192.168.88.53:9092</td>
<td>监听信息，PLAINTEXT表示明文传输</td>
</tr>
<tr>
<td>log.dirs</td>
<td>kafka/logs</td>
<td>kafka数据存放地址，可以填写多个。用”,”间隔</td>
</tr>
<tr>
<td>message.max.bytes</td>
<td>message.max.bytes</td>
<td>单个消息长度限制，单位是字节</td>
</tr>
<tr>
<td>num.partitions</td>
<td>1</td>
<td>默认分区数</td>
</tr>
<tr>
<td>log.flush.interval.messages</td>
<td>Long.MaxValue</td>
<td>在数据被写入到硬盘和消费者可用前最大累积的消息的数量</td>
</tr>
<tr>
<td>log.flush.interval.ms</td>
<td>Long.MaxValue</td>
<td>在数据被写入到硬盘前的最大时间</td>
</tr>
<tr>
<td>log.flush.scheduler.interval.ms</td>
<td>Long.MaxValue</td>
<td>检查数据是否要写入到硬盘的时间间隔。</td>
</tr>
<tr>
<td>log.retention.hours</td>
<td>24</td>
<td>控制一个log保留时间，单位：小时</td>
</tr>
<tr>
<td>zookeeper.connect</td>
<td>192.168.88.21:2181</td>
<td>ZooKeeper服务器地址，多台用”,”间隔</td>
</tr>
</tbody></table>
<h3 id="五、参考文献"><a href="#五、参考文献" class="headerlink" title="五、参考文献"></a><code>五、参考文献</code></h3><ul>
<li><a target="_blank" rel="noopener" href="https://ken.io/note/kafka-cluster-deploy-guide">参考文献1</a></li>
<li><a target="_blank" rel="noopener" href="https://kafka.apache.org/">参考文献2</a></li>
<li><a target="_blank" rel="noopener" href="https://zh.wikipedia.org/zh-cn/Kafka">参考文献3</a></li>
</ul>

                
            </div>
            <hr/>

            

    <div class="reprint" id="reprint-statement">
        
            <div class="reprint__author">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-user">
                        文章作者:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="/about" rel="external nofollow noreferrer">八戒取经路</a>
                </span>
            </div>
            <div class="reprint__type">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-link">
                        文章链接:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="https://codejourney.gitee.io/2021/04/15/Kafka%E9%9B%86%E7%BE%A4%E9%83%A8%E7%BD%B2%E4%B8%8EZookeepeerr%E9%9B%86%E7%BE%A4%E9%83%A8%E7%BD%B2%E5%AE%9E%E6%88%98/">https://codejourney.gitee.io/2021/04/15/Kafka%E9%9B%86%E7%BE%A4%E9%83%A8%E7%BD%B2%E4%B8%8EZookeepeerr%E9%9B%86%E7%BE%A4%E9%83%A8%E7%BD%B2%E5%AE%9E%E6%88%98/</a>
                </span>
            </div>
            <div class="reprint__notice">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-copyright">
                        版权声明:
                    </i>
                </span>
                <span class="reprint-info">
                    本博客所有文章除特別声明外，均采用
                    <a href="https://creativecommons.org/licenses/by/4.0/deed.zh" rel="external nofollow noreferrer" target="_blank">CC BY 4.0</a>
                    许可协议。转载请注明来源
                    <a href="/about" target="_blank">八戒取经路</a>
                    !
                </span>
            </div>
        
    </div>

    <script async defer>
      document.addEventListener("copy", function (e) {
        let toastHTML = '<span>复制成功，请遵循本文的转载规则</span><button class="btn-flat toast-action" onclick="navToReprintStatement()" style="font-size: smaller">查看</a>';
        M.toast({html: toastHTML})
      });

      function navToReprintStatement() {
        $("html, body").animate({scrollTop: $("#reprint-statement").offset().top - 80}, 800);
      }
    </script>



            <div class="tag_share" style="display: block;">
                <div class="post-meta__tag-list" style="display: inline-block;">
                    
                        <div class="article-tag">
                            
                                <a href="/tags/Kafka/">
                                    <span class="chip bg-color">Kafka</span>
                                </a>
                            
                                <a href="/tags/%E9%9B%86%E7%BE%A4/">
                                    <span class="chip bg-color">集群</span>
                                </a>
                            
                                <a href="/tags/Zookeeper/">
                                    <span class="chip bg-color">Zookeeper</span>
                                </a>
                            
                        </div>
                    
                </div>
                <div class="post_share" style="zoom: 80%; width: fit-content; display: inline-block; float: right; margin: -0.15rem 0;">
                    <link rel="stylesheet" type="text/css" href="/libs/share/css/share.min.css">
<div id="article-share">

    
    <div class="social-share" data-sites="twitter,facebook,google,qq,qzone,wechat,weibo,douban,linkedin" data-wechat-qrcode-helper="<p>微信扫一扫即可分享！</p>"></div>
    <script src="/libs/share/js/social-share.min.js"></script>
    

    

</div>

                </div>
            </div>
            
                <style>
    #reward {
        margin: 40px 0;
        text-align: center;
    }

    #reward .reward-link {
        font-size: 1.4rem;
        line-height: 38px;
    }

    #reward .btn-floating:hover {
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2), 0 5px 15px rgba(0, 0, 0, 0.2);
    }

    #rewardModal {
        width: 320px;
        height: 350px;
    }

    #rewardModal .reward-title {
        margin: 15px auto;
        padding-bottom: 5px;
    }

    #rewardModal .modal-content {
        padding: 10px;
    }

    #rewardModal .close {
        position: absolute;
        right: 15px;
        top: 15px;
        color: rgba(0, 0, 0, 0.5);
        font-size: 1.3rem;
        line-height: 20px;
        cursor: pointer;
    }

    #rewardModal .close:hover {
        color: #ef5350;
        transform: scale(1.3);
        -moz-transform:scale(1.3);
        -webkit-transform:scale(1.3);
        -o-transform:scale(1.3);
    }

    #rewardModal .reward-tabs {
        margin: 0 auto;
        width: 210px;
    }

    .reward-tabs .tabs {
        height: 38px;
        margin: 10px auto;
        padding-left: 0;
    }

    .reward-content ul {
        padding-left: 0 !important;
    }

    .reward-tabs .tabs .tab {
        height: 38px;
        line-height: 38px;
    }

    .reward-tabs .tab a {
        color: #fff;
        background-color: #ccc;
    }

    .reward-tabs .tab a:hover {
        background-color: #ccc;
        color: #fff;
    }

    .reward-tabs .wechat-tab .active {
        color: #fff !important;
        background-color: #22AB38 !important;
    }

    .reward-tabs .alipay-tab .active {
        color: #fff !important;
        background-color: #019FE8 !important;
    }

    .reward-tabs .reward-img {
        width: 210px;
        height: 210px;
    }
</style>

<div id="reward">
    <a href="#rewardModal" class="reward-link modal-trigger btn-floating btn-medium waves-effect waves-light red">赏</a>

    <!-- Modal Structure -->
    <div id="rewardModal" class="modal">
        <div class="modal-content">
            <a class="close modal-close"><i class="fas fa-times"></i></a>
            <h4 class="reward-title">你的赏识是我前进的动力</h4>
            <div class="reward-content">
                <div class="reward-tabs">
                    <ul class="tabs row">
                        <li class="tab col s6 alipay-tab waves-effect waves-light"><a href="#alipay">支付宝</a></li>
                        <li class="tab col s6 wechat-tab waves-effect waves-light"><a href="#wechat">微 信</a></li>
                    </ul>
                    <div id="alipay">
                        <img src="/medias/reward/alipay.jpg" class="reward-img" alt="支付宝打赏二维码">
                    </div>
                    <div id="wechat">
                        <img src="/medias/reward/wechat.png" class="reward-img" alt="微信打赏二维码">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('.tabs').tabs();
    });
</script>

            
        </div>
    </div>

    

    

    

    

    

    

    

    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fas fa-chevron-left"></i>&nbsp;上一篇</div>
            <div class="card">
                <a href="/2021/04/15/%E3%80%90%E5%85%A5%E9%97%A8%E3%80%91Zookeeper%E7%9B%B8%E5%85%B3%E6%A6%82%E5%BF%B5%E6%80%BB%E7%BB%93/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/20.jpg" class="responsive-img" alt="【入门】Zookeeper相关概念总结">
                        
                        <span class="card-title">【入门】Zookeeper相关概念总结</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="far fa-clock fa-fw icon-date"></i>2021-04-15
                        </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-user fa-fw"></i>
                            八戒取经路
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/Zookeeper/">
                        <span class="chip bg-color">Zookeeper</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                下一篇&nbsp;<i class="fas fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/2021/04/13/%E5%9F%BA%E4%BA%8E-Spring-Data-%E6%93%8D%E4%BD%9C-ES-%E5%AE%9E%E6%88%98/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/14.jpg" class="responsive-img" alt="基于 Spring Data 操作 ES 实战">
                        
                        <span class="card-title">基于 Spring Data 操作 ES 实战</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="far fa-clock fa-fw icon-date"></i>2021-04-13
                            </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-user fa-fw"></i>
                            八戒取经路
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/Spring-Data-Elasticsearch/">
                        <span class="chip bg-color">Spring Data Elasticsearch</span>
                    </a>
                    
                    <a href="/tags/%E5%AE%9E%E6%88%98/">
                        <span class="chip bg-color">实战</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>

</div>



<!-- 代码块功能依赖 -->
<script type="text/javascript" src="/libs/codeBlock/codeBlockFuction.js"></script>

<!-- 代码语言 -->

<script type="text/javascript" src="/libs/codeBlock/codeLang.js"></script>


<!-- 代码块复制 -->

<script type="text/javascript" src="/libs/codeBlock/codeCopy.js"></script>


<!-- 代码块收缩 -->

<script type="text/javascript" src="/libs/codeBlock/codeShrink.js"></script>


    </div>
    <div id="toc-aside" class="expanded col l3 hide-on-med-and-down">
        <div class="toc-widget card" style="background-color: white;">
            <div class="toc-title"><i class="far fa-list-alt"></i>&nbsp;&nbsp;目录</div>
            <div id="toc-content"></div>
        </div>
    </div>
</div>

<!-- TOC 悬浮按钮. -->

<div id="floating-toc-btn" class="hide-on-med-and-down">
    <a class="btn-floating btn-large bg-color">
        <i class="fas fa-list-ul"></i>
    </a>
</div>


<script src="/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingsOffset: -($(window).height() * 0.4 - 45),
            collapseDepth: Number('0'),
            headingSelector: 'h2, h3, h4'
        });

        // modify the toc link href to support Chinese.
        let i = 0;
        let tocHeading = 'toc-heading-';
        $('#toc-content a').each(function () {
            $(this).attr('href', '#' + tocHeading + (++i));
        });

        // modify the heading title id to support Chinese.
        i = 0;
        $('#articleContent').children('h2, h3, h4').each(function () {
            $(this).attr('id', tocHeading + (++i));
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });

        
        /* 修复文章卡片 div 的宽度. */
        let fixPostCardWidth = function (srcId, targetId) {
            let srcDiv = $('#' + srcId);
            if (srcDiv.length === 0) {
                return;
            }

            let w = srcDiv.width();
            if (w >= 450) {
                w = w + 21;
            } else if (w >= 350 && w < 450) {
                w = w + 18;
            } else if (w >= 300 && w < 350) {
                w = w + 16;
            } else {
                w = w + 14;
            }
            $('#' + targetId).width(w);
        };

        // 切换TOC目录展开收缩的相关操作.
        const expandedClass = 'expanded';
        let $tocAside = $('#toc-aside');
        let $mainContent = $('#main-content');
        $('#floating-toc-btn .btn-floating').click(function () {
            if ($tocAside.hasClass(expandedClass)) {
                $tocAside.removeClass(expandedClass).hide();
                $mainContent.removeClass('l9');
            } else {
                $tocAside.addClass(expandedClass).show();
                $mainContent.addClass('l9');
            }
            fixPostCardWidth('artDetail', 'prenext-posts');
        });
        
    });
</script>

    

</main>




    <footer class="page-footer bg-color">
    
        <link rel="stylesheet" href="/libs/aplayer/APlayer.min.css">
<style>
    .aplayer .aplayer-lrc p {
        
        display: none;
        
        font-size: 12px;
        font-weight: 700;
        line-height: 16px !important;
    }

    .aplayer .aplayer-lrc p.aplayer-lrc-current {
        
        display: none;
        
        font-size: 15px;
        color: #42b983;
    }

    
    .aplayer.aplayer-fixed.aplayer-narrow .aplayer-body {
        left: -66px !important;
    }

    .aplayer.aplayer-fixed.aplayer-narrow .aplayer-body:hover {
        left: 0px !important;
    }

    
</style>
<div class="">
    
    <div class="row">
        <meting-js class="col l8 offset-l2 m10 offset-m1 s12"
                   server="netease"
                   type="playlist"
                   id="503838841"
                   fixed='true'
                   autoplay='false'
                   theme='#42b983'
                   loop='all'
                   order='random'
                   preload='auto'
                   volume='0.7'
                   list-folded='true'
        >
        </meting-js>
    </div>
</div>

<script src="/libs/aplayer/APlayer.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/meting@2/dist/Meting.min.js"></script>

    
    <div class="container row center-align" style="margin-bottom: 0px !important;">
        <div class="col s12 m8 l8 copy-right">
            Copyright&nbsp;&copy;
            
                <span id="year">2019-2021</span>
            
            <span id="year">2019</span>
            <a href="/about" target="_blank">八戒取经路</a>
            |&nbsp;Powered by&nbsp;<a href="https://hexo.io/" target="_blank">Hexo</a>
            |&nbsp;Theme&nbsp;<a href="https://github.com/" target="_blank">Matery</a>
            <br>
            
            
            
            
            
            
            <span id="busuanzi_container_site_pv">
                |&nbsp;<i class="far fa-eye"></i>&nbsp;总访问量:&nbsp;<span id="busuanzi_value_site_pv"
                    class="white-color"></span>&nbsp;次
            </span>
            
            
            <span id="busuanzi_container_site_uv">
                |&nbsp;<i class="fas fa-users"></i>&nbsp;总访问人数:&nbsp;<span id="busuanzi_value_site_uv"
                    class="white-color"></span>&nbsp;人
            </span>
            
            <br>
            
            <br>
            
        </div>
        <div class="col s12 m4 l4 social-link social-statis">
    <a href="https://github.com/blinkfox" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
        <i class="fab fa-github"></i>
    </a>



    <a href="mailto:843355928@qq.com" class="tooltipped" target="_blank" data-tooltip="邮件联系我" data-position="top" data-delay="50">
        <i class="fas fa-envelope-open"></i>
    </a>







    <a href="tencent://AddContact/?fromId=50&fromSubId=1&subcmd=all&uin=843355928" class="tooltipped" target="_blank" data-tooltip="QQ联系我: 843355928" data-position="top" data-delay="50">
        <i class="fab fa-qq"></i>
    </a>







    <a href="/atom.xml" class="tooltipped" target="_blank" data-tooltip="RSS 订阅" data-position="top" data-delay="50">
        <i class="fas fa-rss"></i>
    </a>

</div>
    </div>
</footer>

<div class="progress-bar"></div>


    <!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fas fa-search"></i>&nbsp;&nbsp;搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字"
                   class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script type="text/javascript">
$(function () {
    var searchFunc = function (path, search_id, content_id) {
        'use strict';
        $.ajax({
            url: path,
            dataType: "xml",
            success: function (xmlResponse) {
                // get the contents from search data
                var datas = $("entry", xmlResponse).map(function () {
                    return {
                        title: $("title", this).text(),
                        content: $("content", this).text(),
                        url: $("url", this).text()
                    };
                }).get();
                var $input = document.getElementById(search_id);
                var $resultContent = document.getElementById(content_id);
                $input.addEventListener('input', function () {
                    var str = '<ul class=\"search-result-list\">';
                    var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
                    $resultContent.innerHTML = "";
                    if (this.value.trim().length <= 0) {
                        return;
                    }
                    // perform local searching
                    datas.forEach(function (data) {
                        var isMatch = true;
                        var data_title = data.title.trim().toLowerCase();
                        var data_content = data.content.trim().replace(/<[^>]+>/g, "").toLowerCase();
                        var data_url = data.url;
                        data_url = data_url.indexOf('/') === 0 ? data.url : '/' + data_url;
                        var index_title = -1;
                        var index_content = -1;
                        var first_occur = -1;
                        // only match artiles with not empty titles and contents
                        if (data_title !== '' && data_content !== '') {
                            keywords.forEach(function (keyword, i) {
                                index_title = data_title.indexOf(keyword);
                                index_content = data_content.indexOf(keyword);
                                if (index_title < 0 && index_content < 0) {
                                    isMatch = false;
                                } else {
                                    if (index_content < 0) {
                                        index_content = 0;
                                    }
                                    if (i === 0) {
                                        first_occur = index_content;
                                    }
                                }
                            });
                        }
                        // show search results
                        if (isMatch) {
                            str += "<li><a href='" + data_url + "' class='search-result-title'>" + data_title + "</a>";
                            var content = data.content.trim().replace(/<[^>]+>/g, "");
                            if (first_occur >= 0) {
                                // cut out 100 characters
                                var start = first_occur - 20;
                                var end = first_occur + 80;
                                if (start < 0) {
                                    start = 0;
                                }
                                if (start === 0) {
                                    end = 100;
                                }
                                if (end > content.length) {
                                    end = content.length;
                                }
                                var match_content = content.substr(start, end);
                                // highlight all keywords
                                keywords.forEach(function (keyword) {
                                    var regS = new RegExp(keyword, "gi");
                                    match_content = match_content.replace(regS, "<em class=\"search-keyword\">" + keyword + "</em>");
                                });

                                str += "<p class=\"search-result\">" + match_content + "...</p>"
                            }
                            str += "</li>";
                        }
                    });
                    str += "</ul>";
                    $resultContent.innerHTML = str;
                });
            }
        });
    };

    searchFunc('/search.xml', 'searchInput', 'searchResult');
});
</script>

    <!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fas fa-arrow-up"></i>
    </a>
</div>


    <script src="/libs/materialize/materialize.min.js"></script>
    <script src="/libs/masonry/masonry.pkgd.min.js"></script>
    <script src="/libs/aos/aos.js"></script>
    <script src="/libs/scrollprogress/scrollProgress.min.js"></script>
    <script src="/libs/lightGallery/js/lightgallery-all.min.js"></script>
    <script src="/js/matery.js"></script>

    <!-- Baidu Analytics -->

    <!-- Baidu Push -->

<script>
    (function () {
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        } else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>

    
    <script src="/libs/others/clicklove.js" async="async"></script>
    
    
    <script async src="/libs/others/busuanzi.pure.mini.js"></script>
    

    

    

    <!--腾讯兔小巢-->
    
    

    

    

    
    <script src="/libs/instantpage/instantpage.js" type="module"></script>
    

</body>

</html>
